package com.example.demo.controller;

import com.example.demo.entity.Teacher;
import com.example.demo.service.TeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/teachers")
@CrossOrigin
public class TeacherController {

    @Autowired
    private TeacherService teacherService;

    // 新增教师
    @PostMapping
    public int insertTeacher(@RequestBody Teacher teacher) {
        return teacherService.insertTeacher(teacher);
    }

    // 删除教师
    @DeleteMapping("/{id}")
    public int deleteTeacherById(@PathVariable int id) {
        return teacherService.deleteTeacherById(id);
    }

    // 修改教师
    @PutMapping
    public int updateTeacher(@RequestBody Teacher teacher) {
        return teacherService.updateTeacher(teacher);
    }

    // 查询教师
    @GetMapping("/{id}")
    public Teacher selectTeacherById(@PathVariable int id) {
        return teacherService.selectTeacherById(id);
    }

    // 查询所有教师
    @GetMapping("list")
    public List<Teacher> selectAllTeachers() {
        return teacherService.selectAllTeachers();
    }

    // 联合查询教师及其用户信息
//    @GetMapping("/{id}/user")
//    public Teacher selectTeacherWithUser(@PathVariable int id) {
//        return teacherService.selectTeacherWithUser(id);
//    }
}
